﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ServiceModel.Channels;
using System.Xml;

namespace PSE.ProcessManager.Common.Gateway
{
    [DataContract]
    public class BaseMessage
    {
        /// <summary>
        /// Id da mensagem
        /// </summary>
        [DataMember]
        public int MessageId { get; set; }
        /// <summary>
        /// Id do Processo
        /// </summary>
        [DataMember]
        public int ProcessId { get; set; }

        /// <summary>
        /// Identificação para entrega da mensagem.
        /// </summary>
        [DataMember]
        public string To { get; set; }

        /// <summary>
        /// Identificação do remetente da mensagem.
        /// </summary>
        [DataMember]
        public string From { get; set; }
        /// <summary>
        /// Operação a ser executada.
        /// </summary>
        [DataMember]
        public string Operation { get; set; }
        
        [DataMember]
        internal System.Xml.XmlDictionaryReader Body { get; set; }

        [DataMember]
        internal MessageBuffer Original { get; set; }

        public T RetrieveParameter<T>()
        {
            if (Original != null)
            {
                return Original.CreateMessage().GetBody<T>();
            }

            return default(T);
        }

		public string ParameterType
		{
			get
			{
                if (Original != null)
				{
					//Body.MoveToStartElement();
					//return Body.Name;
                    return Original.CreateMessage().GetReaderAtBodyContents().Name;
				}
				return String.Empty;
			}
		}
    }
}